package com.ghd.dataviz.core.security.impl;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

import static com.fasterxml.jackson.annotation.JsonProperty.Access;

/**
 * @author ：ghd
 * @date ：Created in 2020-03-15 15:47
 * @description：用户身份信息
 * @modified By：
 * @version: $
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDetailsImpl implements UserDetails {
    private Long id;

    /**
     * 用户名称
     */
    private String name;

    /**
     * 用户密码
     */
    @JsonProperty(access = Access.WRITE_ONLY)
    private String password;
    /**
     * 用户角色
     */
    @JsonProperty(access = Access.READ_ONLY)
    private Collection<? extends GrantedAuthority> authorities;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    @JsonProperty(access = Access.WRITE_ONLY)
    public String getPassword() {
        return password;
    }

    @Override
    @JsonProperty(access = Access.WRITE_ONLY)
    public String getUsername() {
        return name;
    }

    @Override
    @JsonProperty(access = Access.WRITE_ONLY)
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    @JsonProperty(access = Access.WRITE_ONLY)
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    @JsonProperty(access = Access.WRITE_ONLY)
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    @JsonProperty(access = Access.WRITE_ONLY)
    public boolean isEnabled() {
        return true;
    }
}
